package com.ray;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class FirstServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        // 从request中获得参数，参数的形式为  FisrtServlet?username=admin
        String username = req.getParameter("username");

        // 使用writer将数据返回到浏览器中
        PrintWriter writer = resp.getWriter();
        writer.println(String.format("hello, %s! this is your first servlet", username));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        doGet(req, resp);
    }
}
